class PingServlet < HTTPServlet::AbstractServlet
 
 
 # handle client ping
 # @param req client request
 # @param rep client reply
 # @return HTTP status
 # \version 1.0
 # \date   Oct 2009
 # \author Elie
 
  def do_GET(req, resp)   
 
   #prune old clients
   pruneClient()
   
   if req.query['name']
     name = req.query['name']
   else
    name = "unamed"
   end
    
    if $clients[name] then
       $clients[name].isAlive()
       resp.body = name + " client sucessfully updated"
       resp.status = 201 #created
    else
       $clients[name] = Client.new(name, req.query['os'], req.query['cpuName'], req.query['cpuBrand'], req.query['cpuNum'], req.query['cpuSpeed'], req.query['memSize'], req.query['gpuName'], req.query['gpuNum'], req.query['gpuSpeed'], req.query['gpuMemSize'] )    
       $clientNum += 1
       resp.body = name + " client sucessfully registered"
       resp.status = 202 #accepted
    end
      #raise HTTPStatus::OK
  end
  alias do_POST do_GET    # let's accept POST request too.
end
